package deepbitview

import javax.net.ssl.X509TrustManager
import javax.net.ssl.SSLContext
import javax.net.ssl.HttpsURLConnection

/**
 * a very simple trustmanager which just ignores certificates for now
 */
class TrustManager implements X509TrustManager {

    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
        return null;
    }

    public void checkClientTrusted(
            java.security.cert.X509Certificate[] certs, String authType) {
    }

    public void checkServerTrusted(
            java.security.cert.X509Certificate[] certs, String authType) {
    }

    static void generateTrustedSSL() {

        TrustManager[] trustAllCerts = new TrustManager[1]

        trustAllCerts[0] = new TrustManager()
        try {
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        } catch (Exception e) {
        }
    }
}
